package com.ypbase.cloud.tags.controller;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.framework.core.log.LoggerFactory;
import com.ypbase.cloud.tags.api.ITagCategoryApi;
import com.ypbase.cloud.tags.api.dto.TagCategoryDto;
import com.ypbase.cloud.tags.common.WebResponse;

@RequestMapping("tagCategory")
@Controller
public class TagCategoryController {

	/**
	 * the logger
	 */
	private static final Logger logger = LoggerFactory.getLogger(TagCategoryController.class);

	@Autowired
	private ITagCategoryApi tagCategoryApi;

	/**
	 * 根据园区编号调用分类信息
	 * 
	 * @param companyId
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/getTagCategory", method = RequestMethod.GET)
	public WebResponse getTagCategory(@RequestParam(value = "companyId") Long companyId) {
		WebResponse response = new WebResponse(null);
		try {
			response.setData(tagCategoryApi.getTagCategoryList(companyId));

		} catch (Throwable e) {
			logger.error("异常", e);
			response.setStatus("-1");
			response.setMessage("" + e.getMessage());
		}
		return response;
	}
	
	
	/**
	 * 新增标签分类
	 * @param tagCategoryDto
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/addTagCategory", method = RequestMethod.POST)
	public WebResponse addTagCategory(@RequestBody TagCategoryDto tagCategoryDto) {
		WebResponse response = new WebResponse(null);
		try {
			tagCategoryApi.addTagCategory(tagCategoryDto);
		} catch (Throwable e) {
            logger.error("异常", e);
            response.setStatus("-1");
            response.setMessage(e.getMessage());
		}	
	    return response;
	}
	
	/**
	 * 删除标签分类
	 * @param tagCategoryDto
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/deleteTagCategory", method = RequestMethod.GET)
	public WebResponse deleteTagCategory(@RequestParam(value = "companyId") Long companyId) {
		WebResponse response = new WebResponse(null);
		try {
			tagCategoryApi.deleteTagCategory(companyId);
		} catch (Throwable e) {
            logger.error("异常", e);
            response.setStatus("-1");
            response.setMessage(e.getMessage());
		}	
	    return response;
	}
}
